Previous | Next | Trail Map | Creating a User Interface | Using Layout Managers


Creating a Custom Layout Manager

Note: Before you start creating a custom layout manager, make sure that no existing layout manager will work. In particular, GridBagLayout(in the API reference documentation) is flexible enough to work in most cases.

To create a custom layout manager, you must create a class that implements the LayoutManager(in the API reference documentation) interface. Besides implementing the five methods required by LayoutManager, layout managers generally implement at least one public constructor and the toString()(in the API reference documentation) method. Layout managers don't actually draw Components. They simply invoke each Component's resize(), move(), and/or reshape() methods to set the Component's size and position.

Here's an example custom layout manager. It lays out components diagonally, from left to right, with one component per row.

Here's the example, running as an applet:


Previous | Next | Trail Map | Creating a User Interface | Using Layout Managers